<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>SOVEREIGN AGENTIC AGI ALPHA AGENT</title>

  <!-- LOAD SOLANA WEB3.JS (Phantom / Solana integration) -->
  <script src="https://unpkg.com/@solana/web3.js@1.76.0/lib/index.iife.js"></script>

  <style>
  /* GLOBAL RESETS & FONTS */
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  html, body {
    width: 100%;
    height: 100%;
    font-family: "Open Sans", sans-serif;
    overflow-x: hidden;
  }

  /* BACKGROUND & THEME (PALE IVORY / GOLD) */
  body {
    background: linear-gradient(135deg, rgba(255,250,235,1), rgba(255,245,220,1));
    color: #333;
    min-height: 100vh;
    line-height: 1.4;
    scroll-behavior: smooth;
    position: relative;
  }

  /* FUSED P5 BACKGROUND + ADVANCED ASI SUPRA-HIEROGLYPHS OVERLAY */
  #p5-background {
    position: fixed;
    top: 0; 
    left: 0;
    width: 100%; 
    height: 100%;
    z-index: -1;
    background: url("https://ipfs.io/ipfs/QmQ6MogCaNn5xMWkFa2jtvYSoiTJXtapp3unTenD65SDak") center center no-repeat;
    background-size: cover;
    opacity: 0.3;
    mix-blend-mode: multiply;
  }
  #asi-hieroglyphs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    background: repeating-linear-gradient(
      160deg,
      transparent 0 10px,
      rgba(255,205,160,0.05) 10px 20px,
      transparent 20px 30px,
      rgba(255,225,200,0.03) 30px 40px
    );
    mix-blend-mode: screen;
  }

  /* HEADER */
  header {
    width: 100%;
    padding: 3rem 1rem 2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  header .agent-image {
    max-width: 500px;
    width: 85%;
    border-radius: 0.5rem;
    box-shadow: 0 0 35px rgba(0,0,0,0.25);
    margin-bottom: 1.5rem;
  }
  header h1 {
    font-family: "Montserrat", sans-serif;
    font-weight: 700;
    font-size: 2.2rem;
    color: #8e6d2a; 
    text-transform: uppercase;
    margin-bottom: 1rem;
    letter-spacing: 0.08em;
  }
  header p.tagline {
    font-size: 1.15rem;
    color: #a28154;
    margin-bottom: 1.5rem;
  }
  header a.cta-button {
    display: inline-block;
    text-decoration: none;
    padding: 0.9rem 1.5rem;
    font-size: 1.15rem;
    font-weight: 600;
    border-radius: 30px;
    color: #fff;
    background: linear-gradient(135deg, #ffd28f, #fbb45c);
    transition: all 0.4s ease;
    box-shadow: 0 0 15px rgba(255,255,255,0.3);
  }
  header a.cta-button:hover {
    box-shadow: 0 0 35px rgba(255,255,255,0.5);
    transform: scale(1.06);
  }

  /* MAIN CONTAINER */
  main {
    width: 90%;
    max-width: 1100px;
    margin: 2rem auto;
    background-color: rgba(255,255,255, 0.8);
    backdrop-filter: blur(5px);
    border-radius: 0.5rem;
    padding: 2rem;
    box-shadow: 0 0 25px rgba(255,255,255,0.5);
    text-align: center;
  }
  h2 {
    font-family: "Montserrat", sans-serif;
    font-weight: 700;
    font-size: 1.7rem;
    color: #8e6d2a;
    margin: 1rem 0;
  }
  p {
    margin-bottom: 1.2rem;
    font-size: 1rem;
    color: #333;
    line-height: 1.6;
    text-align: center;
  }
  .install-btn {
    display: inline-block;
    text-decoration: none;
    padding: 0.9rem 1.5rem;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: 30px;
    color: #fff;
    background: linear-gradient(135deg, #ffd28f, #fbb45c);
    transition: all 0.4s ease;
    box-shadow: 0 0 15px rgba(255,255,255,0.3);
    cursor: pointer;
  }
  .install-btn:hover {
    box-shadow: 0 0 35px rgba(255,255,255,0.5);
    transform: scale(1.06);
  }
  #access-message {
    margin-top: 1rem;
    font-weight: bold;
    font-size: 1rem;
    color: #8e6d2a;
    white-space: pre-line;
  }
  @media (max-width: 768px) {
    header .agent-image { max-width: 300px; }
    header h1 { font-size: 1.6rem; margin-bottom: 0.7rem; }
    header p.tagline { font-size: 1rem; }
    header a.cta-button { font-size: 1rem; }
    main { padding: 1.5rem; }
  }
  </style>
</head>
<body>

<div id="p5-background"></div>
<div id="asi-hieroglyphs"></div>

<header>
  <img class="agent-image"
       src="https://ipfs.io/ipfs/QmQ6MogCaNn5xMWkFa2jtvYSoiTJXtapp3unTenD65SDak"
       alt="AGI ALPHA AGENT">
  <h1>SOVEREIGN AGENTIC AGI ALPHA</h1>
  <p class="tagline">Gated by ≥ 1,000,000 $AGIALPHA</p>
  <a class="cta-button"
     href="https://dexscreener.com/solana/8zq3vBuoy66dur6dhrA4aqnrtGg9yZyRAp51BTBpEXj"
     target="_blank" rel="noopener">
    Buy $AGIALPHA Tokens
  </a>
  <p style="margin-top:1rem; font-size:0.95rem; color:#8e6d2a;">
    Contract Address (CA): 
    <strong>tWKHzXd5PRmxTF5cMfJkm2Ua3TcjwNNoSRUqx6Apump</strong>
  </p>
</header>

<main>
  <h2>One-Click Install &amp; Launch</h2>
  <p>
    Download &amp; run this installer to locally deploy the <br>
    <strong>SOVEREIGN AGENTIC AGI ALPHA AGENT</strong> on your machine.
  </p>
  <button class="install-btn" onclick="startDownload()">
    Download &amp; Install
  </button>
  <p style="margin-top:1rem; font-size:0.85rem; color:#666;">
    Then run:
    <code>chmod +x install_and_launch.sh</code>, 
    <code>./install_and_launch.sh</code>
  </p>

  <hr style="margin: 2rem 0;">

  <button id="connect-wallet" class="install-btn">Connect Wallet</button>
  <p id="access-message"></p>
</main>

<!-- p5.js star background -->
<script src="https://cdn.jsdelivr.net/npm/p5@1.6.0/lib/p5.min.js"></script>
<script>
let starCount = 33;
let stars = [];
let containerRadius = 300;
let angle = 0;

function setup() {
  let cnv = createCanvas(windowWidth, windowHeight, WEBGL);
  cnv.parent("p5-background");
  colorMode(HSB, 360, 100, 100);
  noStroke();
  for (let i = 0; i < starCount; i++) {
    stars.push(new Star());
  }
}

function draw() {
  background(0, 0.08);
  rotateY(angle * 0.001);
  rotateX(angle * 0.0007);
  angle += 0.2;
  let zoom = sin(frameCount * 0.002) * 150;
  translate(0, 0, zoom);
  push(); noFill(); stroke(50, 0, 100, 20); sphere(containerRadius); pop();
  for (let s of stars) { s.update(); s.render(); }
}

class Star {
  constructor() {
    let r = random(containerRadius);
    let theta = random(TWO_PI);
    let phi = random(PI);
    this.x = r * sin(phi) * cos(theta);
    this.y = r * sin(phi) * sin(theta);
    this.z = r * cos(phi);
    this.vx = random(-1, 1);
    this.vy = random(-1, 1);
    this.vz = random(-1, 1);
    this.hue = random(360);
    this.size = random(4, 7);
  }
  update() {
    this.x += this.vx; this.y += this.vy; this.z += this.vz;
    let magPos = sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
    if (magPos > containerRadius - this.size) {
      let nx = this.x / magPos;
      let ny = this.y / magPos;
      let nz = this.z / magPos;
      let dot = this.vx*nx + this.vy*ny + this.vz*nz;
      this.vx -= 2*dot*nx;
      this.vy -= 2*dot*ny;
      this.vz -= 2*dot*nz;
    }
  }
  render() {
    push();
    translate(this.x, this.y, this.z);
    fill(this.hue,80,100);
    sphere(this.size);
    pop();
    this.hue += 0.4;
    if (this.hue>=360) this.hue=0;
  }
}

function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
}

function startDownload() {
  alert("Downloading 'install_and_launch.sh'...\nThen run it to install & launch the AGI ALPHA AGENT!");
  window.location.href = "install_and_launch.sh";
}

// Phantom gating demonstration
const TOKEN_MINT = "tWKHzXd5PRmxTF5cMfJkm2Ua3TcjwNNoSRUqx6Apump";
const REQUIRED_BALANCE = 1000000;
const RPC_URL = "https://solana-mainnet.g.alchemy.com/v2/KT1RV46Eoje4kL-SC2pSANHTVm6-wgwF";
const { Connection, PublicKey } = solanaWeb3;

document.getElementById("connect-wallet").addEventListener("click", async () => {
  if (!window.solana || !window.solana.isPhantom) {
    alert("Phantom Wallet not found! Please install or enable Phantom.");
    return;
  }
  try {
    const connection = new Connection(RPC_URL, "confirmed");
    const wallet = window.solana;
    const response = await wallet.connect();
    const pubkey = response.publicKey.toString();
    document.getElementById("access-message").innerText =
      `Connected wallet: ${pubkey}\nChecking balance...`;

    // get all token accounts for user
    const tokenAccounts = await connection.getParsedTokenAccountsByOwner(
      new PublicKey(pubkey),
      { programId: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") }
    );
    let balance = 0;
    tokenAccounts.value.forEach(acc => {
      let info = acc.account.data.parsed.info;
      if (info.mint === TOKEN_MINT) {
        balance += info.tokenAmount.uiAmount;
      }
    });
    if (balance >= REQUIRED_BALANCE) {
      document.getElementById("access-message").innerText =
        `🚀 You hold ${balance.toLocaleString()} $AGIALPHA.\nAccess Granted!`;
    } else {
      document.getElementById("access-message").innerText =
        `⛔ You hold ${balance.toLocaleString()} $AGIALPHA (<1,000,000).\nAccess Denied.`;
    }
  } catch (err) {
    console.error("Phantom connect error:", err);
    alert("Failed to connect or check balance.");
  }
});
</script>
</body>
</html>

